/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plagiadetector.driver;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import plagiadetector.datatype.GramCounter;
import plagiadetector.datatype.PANCorpus;
import plagiadetector.datatype.TextSegment;
import plagiadetector.detector.StamaDetector;
import plagiadetector.detector.StamaDetector;
import plagiadetector.utility.DummyCharCounter;
import plagiadetector.utility.FileUtils;
import plagiadetector.utility.PANXMLParser;

/**
 *
 * @author Dell
 */
public class StamaDetectorDriver {
    public static void main(String[] args){

        StamaDetector sd = new StamaDetector();
        String xmladdr = "corpusexamples\\PAN2011\\suspicious-document00016.xml";
        
        System.out.println("SETTING XML");
        
        PANCorpus panc = PANXMLParser.parseXML(xmladdr);
        
        System.out.println("SETTING RAW TEXT");
        
        sd.setRawText("There was great consternation in Fairy eat !!!");        
        sd.setWindowLength(10);
        sd.setWindowStep(5);
        sd.setWindowLengthThreshold(15);
        
//        sd.setRawText(panc.getCorpusText());
       
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("RAW TEXT, LENGTH : "+sd.getRawText().length());
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println(sd.getRawText());
        
        sd.doPreprocessing();
        
         System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("PREPROCESSED TEXT, LENGTH : "+sd.getPreprocessedText().length());
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println(sd.getPreprocessedText());
    
        sd.doSegmentation();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("GENERATED SEGMENTS");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        for(int i = 0; i < sd.getNumOfTextSegments() ; i++){
            System.out.println("################################################");
            System.out.println("SEGMENT NUMBER "+i+", OFFSET : "+sd.getTextSegment(i).offset+", LENGTH : "+sd.getTextSegment(i).segmentText.length());
            System.out.println("################################################");
            System.out.println(sd.getTextSegment(i).segmentText);
            
            System.out.println("Segment number "+i+"- length : "+sd.getTextSegment(i).segmentText.length()+" alphabetic char count : "+DummyCharCounter.countAphabeticChars(sd.getTextSegment(i).segmentText));
            if(i > 0){
                System.out.println("Step from segment number "+i+" against segment number "+(i-1)+" : "+(sd.getTextSegment(i).offset-sd.getTextSegment(i-1).offset));
            }
        }
        
        sd.doStylometricExtraction();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("EXTRACTED FEATURES");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println("################################################");
        System.out.println("WHOLE DOCUMENT FEATURES, NUMBER OF GRAMS : "+sd.docgrams.size());
        System.out.println("################################################");
  
/*
        for(String s : sd.docgrams){
            System.out.println("["+s+"]");
        }
       
*/
        for(int i = 0; i < sd.windowgrams.size(); i++){
             System.out.println("################################################");
             System.out.println("SEGMENT NUMBER "+i+" FEATURES, NUMBER OF GRAMS : "+sd.windowgrams.get(i).size());
             System.out.println("################################################");
/*
             for(String s : sd.windowgrams.get(i)){
                 System.out.println("["+s+"]");
             } 
*/
        }
        
        sd.doStylometricQA();
        
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        System.out.println("QUANTIFIED FEATURES");
        System.out.println("---------------------------------------------------------------------------------------------------------------------------------------");
        
        System.out.println("################################################");
        System.out.println("WHOLE DOCUMENT QUANTIFIED FEATURES, NUMBER OF UNIQUE FEATURES : "+sd.docprofile.size());
        System.out.println("################################################");
  
        Iterator itx = sd.docprofile.entrySet().iterator();
        GramCounter gc;
        
        while(itx.hasNext()){
            gc = (GramCounter)((Map.Entry)itx.next()).getValue();
            System.out.println("Gram : ["+gc.text+"] , Freq : "+gc.occurrence);
        } 

        
/*   
 *      
        for(int i = 0; i < sd.windowgrams.size(); i++){
             System.out.println("################################################");
             System.out.println("SEGMENT NUMBER "+i+" QUANTIFIED FEATURES, NUMBER OF UNIQUE FEATURES : "+sd.windowgrams.get(i).size());
             System.out.println("################################################");
             for(GramCounter gc : sd.windowgrams.get(i)){
                System.out.println("Gram : "+gc.text+", Freq : "+gc.occurrence);
             }
        }
*/
        
        System.out.println("################################################");
        System.out.println("WINDOW STYLES");
        System.out.println("################################################");
  
        for(int i = 0; i < sd.wschange.size(); i++){
            System.out.println("Window number : "+i+" style change : "+sd.wschange.get(i));            
        }
        System.out.println("################################################");
        System.out.println("WINDOW STYLE MEAN AND STANDARD DEVIATION");
        System.out.println("################################################");
       
        System.out.println("Window style mean : "+sd.getAllWindowStyleMean()+", standard deviation : "+sd.getAllWindowStyleStandardDeviaton());
        
        System.out.println("----------------------------------------------------");
        System.out.println("ANALYSIS - DETECTED CASES");
        System.out.println("----------------------------------------------------");
        
        for(int i = 0; i < sd.getNumOfCases(); i++){
            System.out.println("Case Number : "+i+" Offset : "+sd.getCase(i).offset+" Length : "+sd.getCase(i).length);
        }
    }
}
